#include<iostream>
#include<vector>
using namespace std;
class Solution 
{
public:
    int findPoisonedDuration(vector<int>& timeSeries, int duration) 
    {
        int n=timeSeries.size();
        int ret=0;
        for(int i=0;i<n-1;i++)
        {
            int sub=timeSeries[i+1]-timeSeries[i];
            if(sub<duration)//当中毒时刻差值小于中毒影响，会重置中毒影响
                ret+=sub;//本次中毒影响仅为差值
            else
                ret+=duration;
        }
        ret+=duration;//处理最后一次中毒
        return ret;
    }
};